package cz.mff.kusad5am.hb.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.mff.kusad5am.hb.dbsim.HostelsDBImitation;
import cz.mff.kusad5am.hb.schema.reservationlist.Hostel;
import cz.mff.kusad5am.hb.schema.reservationlist.HostelReservation;

public class ReservationWorker {

	static Map<Integer, List<HostelReservation>> reservations;
	
	public ReservationWorker() {
		reservations = new HashMap<Integer, List<HostelReservation>>();
	}
	
	public HostelReservation createReservation(String start, String guests, String nights, int hostelId, int roomId, int customerId) {
		if (reservations.get(customerId) == null) {
			List<HostelReservation> ress = new ArrayList<HostelReservation>();
			reservations.put(customerId, ress);
		}
		
		List<HostelReservation> ress = reservations.get(customerId);
		
		HostelReservation res = new HostelReservation();
		Hostel hostel = new Hostel();
		cz.mff.kusad5am.hb.schema.list.Hostel hh = HostelsDBImitation.getIntance().getHostel(hostelId);
		hostel.setAddress(hh.getAddress());
		hostel.setCity(hh.getCity());
		hostel.setCountry(hh.getCountry());
		hostel.setId(hh.getId());
		hostel.setName(hh.getName());
		hostel.setZipCode(hh.getZipCode());
		res.setHostel(hostel);
		res.setArrivalDate(null);
		res.setFinalPrice("6666");
		res.setId(ress.size()+1);
		res.setNumberOfGuests(Integer.parseInt(guests));
		res.setNumerOfNights(Integer.parseInt(guests));
		res.setReservationStatus("reserved");
		
		// add reservation to list
		ress.add(res);
		return res;
	}
	
	public HostelReservation getReservation(Integer custId, Integer resId) {
		return reservations.get(custId).get(resId);
	}
	
	public List<HostelReservation> getListOfReservation(int id) {
		if (reservations.get(id) == null) {
			List<HostelReservation> ress = new ArrayList<HostelReservation>();
			reservations.put(id, ress);
		}
		
		List<HostelReservation> ress = reservations.get(id);
		
		return ress;
	}
	
	public void cancelReservation(Integer custId, Integer resId) {
		reservations.remove(resId);
	}
}
